/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logger;

import java.util.Calendar;

/**
 *
 * @author Tuan
 */
public class Logger implements ILog{
    private String name;
    
    public Logger(String name){
        this.name = name;
    }
    
    private Logger(){}

    public void info(String message) {              
        System.out.println(outputDateUsingCalendar() + " " + name + " info " + message);
    }

    public void error(String message) {
        System.out.println(outputDateUsingCalendar() + " " + name + " error " + message);
    }    
    
    private String outputDateUsingCalendar() {
        Calendar calendar = Calendar.getInstance();        
        StringBuffer sb = new StringBuffer();
 
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        sb.append(numberToString(day));
        sb.append("-");
        int month = calendar.get(Calendar.MONTH) + 1;
        sb.append(numberToString(month));
        sb.append("-");
        sb.append(calendar.get(Calendar.YEAR)); 
       return sb.toString();
    }
    
    private String numberToString(int value) {
        String valStr = Integer.toString(value);
        return (value < 10) ? "0" + valStr: valStr;
    }
    
}
